package com.ruoyi.iptv.video.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iptv.video.domain.IptvVideoType;
import com.ruoyi.iptv.video.service.IIptvVideoTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 点播分类Controller
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/video/type")
public class IptvVideoTypeController extends BaseController
{
    private String prefix = "video/type";

    @Autowired
    private IIptvVideoTypeService iptvVideoTypeService;

    @RequiresPermissions("video:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询点播分类树列表
     */
    @RequiresPermissions("video:type:list")
    @PostMapping("/list")
    @ResponseBody
    public List<IptvVideoType> list(IptvVideoType iptvVideoType)
    {
        List<IptvVideoType> list = iptvVideoTypeService.selectIptvVideoTypeList(iptvVideoType);
        return list;
    }

    /**
     * 导出点播分类列表
     */
    @RequiresPermissions("video:type:export")
    @Log(title = "点播分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IptvVideoType iptvVideoType)
    {
        List<IptvVideoType> list = iptvVideoTypeService.selectIptvVideoTypeList(iptvVideoType);
        ExcelUtil<IptvVideoType> util = new ExcelUtil<IptvVideoType>(IptvVideoType.class);
        return util.exportExcel(list, "点播分类数据");
    }

    /**
     * 新增点播分类
     */
    @GetMapping(value = { "/add/{id}", "/add/" })
    public String add(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("iptvVideoType", iptvVideoTypeService.selectIptvVideoTypeById(id));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存点播分类
     */
    @RequiresPermissions("video:type:add")
    @Log(title = "点播分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IptvVideoType iptvVideoType)
    {
        return toAjax(iptvVideoTypeService.insertIptvVideoType(iptvVideoType));
    }

    /**
     * 修改点播分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IptvVideoType iptvVideoType = iptvVideoTypeService.selectIptvVideoTypeById(id);
        mmap.put("iptvVideoType", iptvVideoType);
        return prefix + "/edit";
    }

    /**
     * 修改保存点播分类
     */
    @RequiresPermissions("video:type:edit")
    @Log(title = "点播分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IptvVideoType iptvVideoType)
    {
        return toAjax(iptvVideoTypeService.updateIptvVideoType(iptvVideoType));
    }

    /**
     * 删除
     */
    @RequiresPermissions("video:type:remove")
    @Log(title = "点播分类", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("id") Long id)
    {
        return toAjax(iptvVideoTypeService.deleteIptvVideoTypeById(id));
    }

    /**
     * 选择点播分类树
     */
    @GetMapping(value = { "/selectTypeTree/{id}", "/selectTypeTree/" })
    public String selectTypeTree(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("iptvVideoType", iptvVideoTypeService.selectIptvVideoTypeById(id));
        }
        return prefix + "/tree";
    }

    /**
     * 加载点播分类树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = iptvVideoTypeService.selectIptvVideoTypeTree();
        return ztrees;
    }
}
